package com.WKH;

import com.publicClass.Role;
import com.publicClass.User;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import com.util.Vessel;

import java.util.Scanner;

public class SchoolClass {

//    private String classId;
    private String className;
//    private List<User> students;
    private long teacherId;
    private String teacherName;
    public SchoolClass() {
    }

    public SchoolClass(String className, long teacherId, String teacherName) {
        this.className = className;
        this.teacherId = teacherId;
        this.teacherName = teacherName;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getTeacherName() {
        return teacherName;
    }

    public void setTeacherName(String teacherName) {
        this.teacherName = teacherName;
    }

    public long getTeacherId() {
        return teacherId;
    }

    public void setTeacherId(long teacherId) {
        this.teacherId = teacherId;
    }

    //添加班级
    public static void addClass(){
        boolean isFlag = true;
        do {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入您要添加的班级名称");
            String className = scanner.next();
            System.out.println("请输入您要添加的班主任工号");
            long teacherId = scanner.nextLong();
            System.out.println("请输入您要添加的班级教师姓名");
            String teacherName = scanner.next();
            SchoolClass newSchoolClass = new SchoolClass(className,teacherId,teacherName);
            for (User user:Vessel.users) {
                if (user.getRole().equals(Role.Teacher)){
                    if (user.getId() == teacherId && user.getName().equals(teacherName)){
                        user.setSchoolClass(className);
                        break;
                    }else{
                        System.out.println("并未找到该教师的信息，请重新操作");
                        isFlag = false;
                    }
                }
            }
            Vessel.schoolClasses.add(newSchoolClass);
            System.out.println("班级名称\t\t\t班主任id\t\t\t班主任姓名");
            for (SchoolClass schoolClass :Vessel.schoolClasses){
                System.out.println(schoolClass.schoolClassToString());
            }
            System.out.println("添加完成，请问是否继续添加(y/n)");
            String next = scanner.next();
            if (next.equals("y")){
                isFlag = true;
            }else if (next.equals("n")){
                isFlag = false;
            }
        }while (isFlag);
    }

    //删除班级
    public static void delClass(){
        Scanner scanner = new Scanner(System.in);
        boolean isFlag = true;
        do {
            System.out.println("请输入您要删除的班级姓名");
            String calssName = scanner.next();
            for (int i = 0; i < Vessel.schoolClasses.size(); i++) {
                if (Vessel.schoolClasses.get(i).getClassName().equals(calssName)){
                    Vessel.schoolClasses.remove(i);
                    for (int j = 0; j < Vessel.users.size(); j++) {
                        if (Vessel.users.get(j).getSchoolClass().equals(calssName)){
                            Vessel.users.get(j).setSchoolClass(null);
                        }
                    }
                    for (SchoolClass schoolClass :Vessel.schoolClasses){
                        System.out.println(schoolClass.schoolClassToString());
                    }
                    System.out.println("删除已完成，请问是否继续删除(y/n)");
                    String next = scanner.next();
                    if (next.equals("y")){
                        isFlag = true;
                    }else if (next.equals("n")){
                        isFlag = false;
                    }
                }else{
                    System.out.println("未找到您要删除的班级，请重新操作");
                    isFlag = false;
                }
            }
        }while (isFlag);
    }

    //修改班级
    public static void updateClass(){

    }

    //查询班级
    public static void findClass(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请您输入您要查找的班级名称");
        String next = scanner.next();
        for (SchoolClass schoolClass : Vessel.schoolClasses) {
            if (schoolClass.getClassName().equals(next)){
                System.out.println(schoolClass.schoolClassToString());
            }
        }
    }

    public String schoolClassToString(){
        return getClassName()+"\t\t\t"+getTeacherId()+"\t\t\t"+getTeacherName();
    }

    //test
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请选择您的操作");
        System.out.println("1.添加");
        System.out.println("2.删除");
        System.out.println("3.修改");
        System.out.println("4.查询");
        int i = scanner.nextInt();
        switch (i){
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
            case 4:
                break;
        }
    }
}
